/**
 * <p>代码配置选择控件，下拉数据来自系统代码配置字典表，在代码字配置典变动的时候“内存同步”后会更新codeconfigdata.js</p>
 * xtype = cceafcodefield

 * @module Ext-ux-cceaf-control
 * @class cceaf.control.CodeConfigField
 * @extends Ext.form.ComboBox
 * @since 1.0
 */
Ext.define('cceaf.control.CodeConfigField',{
	extend: 'Ext.form.field.ComboBox', 
	requires: [
	    'cceaf.ControlDefaultConfig'
    ],
    alias: 'widget.cceafcodeconfigfield',

	constructor: function(config){
		config = config || {};

		var value;
		if(config.value){
			value = config.value;
		}
		else{
			value = '';
		}
		
		var queryMode;
		if(config.queryMode){
			queryMode = config.queryMode;
		}
		else{
			queryMode = 'local';
		}
		
		var store = config.store;
		if (queryMode == 'local') {
			var data = eval('_jsonCodeConfig.' + config.codeType);
			if (data == null) {
				data = [];
			}
			
			store = new Ext.data.Store({
		    	model: 'cceaf.model.main.CceafCode',
		    	//autoLoad: true,
		    	data: data
		    });
		} else {
			store = new Ext.data.Store({
		    	model: 'cceaf.model.main.CceafCode',
		    	//autoLoad: true,
		    	proxy: {
		    		type: 'ajax',
		    		url: 'pageDataProvider!getCodeList.action',
		    		extraParams: {codetype: config.codeType}
				}
		    });
		}
		
		var defaultFieldWidth = cceaf.ControlDefaultConfig.DEFAULT_FIELD_WIDTH;
		config = Ext.applyIf(config, {
			width: defaultFieldWidth,
			typeAhead: true,
			editable: true,
			autoSelect: true,
			autoRender: true,
			
		    triggerAction: 'all',
		    lazyRender: false,
		    queryMode: queryMode,
		    forceSelection: true,
		    store: store,
		    valueField: 'value',
		    displayField: 'name',
		    value: value,
		    listeners: {
		    	load: function(){
		    		this.setValue(this.store.getAt(0).data.value);
		    	}
	        }
		});

		cceaf.control.CodeConfigField.superclass.constructor.apply(this, arguments);
	},
	
	/**
	 * 代码类型，必须填写
	 *
     * @property codeType 
     * @type String
     * @default null
     */
	codeType: null,
	
	/**
	 * 代码值
	 *
     * @property value 
     * @type String
     * @default ''
     */
	value: '',
	
	/**
	 * 查询方式
	 *
     * @property queryMode 
     * @type String
     * @default 'local'
     */
	queryMode: 'local',
	
	allowBlank: true
});